#!/bin/bash -x


###############################################################################
#
# usage
#
###############################################################################
usage ()
{
  set +x
  echo "Usage: `basename $0` [destination_directory]"
  echo ""
  echo "destination_directory   This is the location of the directory"
  echo "                         for the packaged files."
  echo ""
  echo "If not supplied a destination directory of 'pkg' will be used."
  echo ""
  echo "Examples:"
  echo "`basename $0` dts-dirname"
  exit
}

case $1 in
  -[?hH]*) usage; exit;
esac

PKG=$1
if test x"$PKG" == x""
then
  PKG=pkg
fi

rm -rf $PKG

mkdir -p $PKG/lib

# Statically linked
cp $DDS_ROOT/lib/libDCPSInfoRepoServ.so.* $PKG/lib/
cp $DDS_ROOT/lib/libFederator.so.*        $PKG/lib/
cp $DDS_ROOT/lib/libInfoRepoLib.so.*      $PKG/lib/
cp $DDS_ROOT/lib/libOpenDDS_Dcps.so.*     $PKG/lib/

# For statically linked
cp $DDS_ROOT/lib/libSimpleTcp.so.*             $PKG/lib/
cp $DDS_ROOT/lib/libOpenDDS_Udp.so.*           $PKG/lib/
cp $DDS_ROOT/lib/libOpenDDS_Multicast.so.*     $PKG/lib/

# For dynamic linking
# NOTE: This allows only a single version of the library to be present
#       during package creation.  Run 'make realclean;make' if the
#       version has been updated since the last build.
(cd $PKG/lib; ln -s libSimpleTcp.so.*             libSimpleTcp.so)
(cd $PKG/lib; ln -s libOpenDDS_Udp.so.*           libOpenDDS_Udp.so)
(cd $PKG/lib; ln -s libOpenDDS_Multicast.so.*     libOpenDDS_Multicast.so)

# Statically linked
cp $ACE_ROOT/lib/libACE.so.*                $PKG/lib/
cp $ACE_ROOT/lib/libTAO_AnyTypeCode.so.*    $PKG/lib/
cp $ACE_ROOT/lib/libTAO_ImR_Client.so.*     $PKG/lib/
cp $ACE_ROOT/lib/libTAO_IORTable.so.*       $PKG/lib/
cp $ACE_ROOT/lib/libTAO_PortableServer.so.* $PKG/lib/
cp $ACE_ROOT/lib/libTAO.so.*                $PKG/lib/
cp $ACE_ROOT/lib/libTAO_Svc_Utils.so.*      $PKG/lib/
cp $ACE_ROOT/lib/libTAO_CodecFactory.so.*   $PKG/lib/
cp $ACE_ROOT/lib/libTAO_AnyTypeCode.so.*    $PKG/lib/
cp $ACE_ROOT/lib/libTAO_Codeset.so.*        $PKG/lib/
cp $ACE_ROOT/lib/libTAO_PI.so.*             $PKG/lib/

# For dynamic linking
(cd $PKG/lib; ln -s libTAO_CodecFactory.so.*     libTAO_CodecFactory.so)
(cd $PKG/lib; ln -s libTAO_AnyTypeCode.so.*      libTAO_AnyTypeCode.so)
(cd $PKG/lib; ln -s libTAO_Codeset.so.*          libTAO_Codeset.so)
(cd $PKG/lib; ln -s libTAO_PI.so.*               libTAO_PI.so)

mkdir -p $PKG/bin/PerlDDS
mkdir -p $PKG/bin/PerlACE

# Perl modules
cp $DDS_ROOT/bin/PerlDDS/Run_Test.pm          $PKG/bin/PerlDDS/

cp $DDS_ROOT/bin/PerlDDS/ProcessFactory.pm    $PKG/bin/PerlDDS/
cp $DDS_ROOT/bin/PerlDDS/Process.pm           $PKG/bin/PerlDDS/
cp $DDS_ROOT/bin/PerlDDS/Cross_Sync.pm        $PKG/bin/PerlDDS/
cp $DDS_ROOT/bin/PerlDDS/Cross_Sync_Common.pm $PKG/bin/PerlDDS/

cp $ACE_ROOT/bin/PerlACE/ConfigList.pm      $PKG/bin/PerlACE/
cp $ACE_ROOT/bin/PerlACE/Process_Unix.pm    $PKG/bin/PerlACE/
cp $ACE_ROOT/bin/PerlACE/ProcessVX_Win32.pm $PKG/bin/PerlACE/
cp $ACE_ROOT/bin/PerlACE/TestTarget.pm      $PKG/bin/PerlACE/
cp $ACE_ROOT/bin/PerlACE/MSProject.pm       $PKG/bin/PerlACE/
cp $ACE_ROOT/bin/PerlACE/Process_VMS.pm     $PKG/bin/PerlACE/
cp $ACE_ROOT/bin/PerlACE/Process_Win32.pm   $PKG/bin/PerlACE/
cp $ACE_ROOT/bin/PerlACE/ProcessLVRT.pm     $PKG/bin/PerlACE/
cp $ACE_ROOT/bin/PerlACE/ProcessVX.pm       $PKG/bin/PerlACE/
cp $ACE_ROOT/bin/PerlACE/Run_Test.pm        $PKG/bin/PerlACE/
cp $ACE_ROOT/bin/PerlACE/Process.pm         $PKG/bin/PerlACE/
cp $ACE_ROOT/bin/PerlACE/ProcessVX_Unix.pm  $PKG/bin/PerlACE/
cp $ACE_ROOT/bin/PerlACE/TestTarget_LVRT.pm $PKG/bin/PerlACE/

# Executables
cp $DDS_ROOT/bin/DCPSInfoRepo                        $PKG/bin/
cp $DDS_ROOT/bin/odds_repoctl                        $PKG/bin/
cp $DDS_ROOT/performance-tests/Bench/bin/testprocess $PKG/bin/
cp $DDS_ROOT/performance-tests/Bench/bin/run_test    $PKG/bin/

mkdir -p $PKG/etc

# Configuration
cp $DDS_ROOT/performance-tests/Bench/etc/*.ini    $PKG/etc/

mkdir -p $PKG/tests/scenarios
mkdir -p $PKG/tests/latency
mkdir -p $PKG/tests/scaling
mkdir -p $PKG/tests/spray
mkdir -p $PKG/tests/thru

# Test scenarios
cp $DDS_ROOT/performance-tests/Bench/tests/scenarios/*.ini $PKG/tests/scenarios
cp $DDS_ROOT/performance-tests/Bench/tests/latency/*.ini $PKG/tests/latency
cp $DDS_ROOT/performance-tests/Bench/tests/scaling/*.ini $PKG/tests/scaling
cp $DDS_ROOT/performance-tests/Bench/tests/spray/*.ini $PKG/tests/spray
cp $DDS_ROOT/performance-tests/Bench/tests/thru/*.ini $PKG/tests/thru

# test running scripts
cp $DDS_ROOT/performance-tests/Bench/tests/latency/run_test.pl $PKG/tests/latency
cp $DDS_ROOT/performance-tests/Bench/tests/latency/test_list.txt $PKG/tests/latency
cp $DDS_ROOT/performance-tests/Bench/tests/thru/run_test.pl $PKG/tests/thru
cp $DDS_ROOT/performance-tests/Bench/tests/thru/test_list.txt $PKG/tests/thru

